<%--
  Created by IntelliJ IDEA.
  User: 27056
  Date: 2022/7/1
  Time: 14:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增商品</title>
    <script src="js/jquery-1.8.3.js"></script>
</head>
<body>
        <h1 style="text-align: center">添加元宇宙商品</h1>
        <form action="metaverseProductAddServlet" method="post" id="form">
            <table border="1" style="border-collapse: collapse;background-color: cornflowerblue;margin: 0px auto;">
                <tr>
                    <td>商品名称:</td>
                    <td><input type="text" name="name" id="name"></td>
                </tr>
                <tr>
                    <td>商品描述:</td>
                    <td><textarea style="width: 200px;height: 100px" type="text" name="desc" id="desc"></textarea></td>
                </tr>
                <tr>
                    <td>商品价格:</td>
                    <td><input type="text" name="price" id="price"></td>
                </tr>
                <tr>
                    <td>商品状态:</td>
                    <td><input checked type="radio" value="1" name="flag">上架 <input type="radio" value="0" name="flag">下架</td>
                </tr>
                <tr>
                    <td>操作:</td>
                    <td><input type="submit" value="新增"><input type="reset" value="重置"></td>
                </tr>
            </table>
        </form>
</body>
<script>
    $("#form").submit(function (){
        if($("#name").val().trim().length==0){
            alert("商品名称不能为空!");
            $("#name").focus();
            return false;
        }
        if($("#desc").val().trim().length==0){
            alert("商品描述不能为空!");
            $("#desc").focus();
            return false;
        }
        let fig = /^(\d+).\d{2}$/
        if($("#price").val().trim().length==0){
            alert("商品价格不能为空!");
            $("#price").focus();
            return false;
        }else if(!fig.test($("#price").val())){
            alert("商品价格必须是保留两位小数!");
            $("#price").focus();
            return false;
        }
    })
</script>
</html>
